<html>
<head>
<title>LoginFrame.java</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.s0 { color: #a9b7c6;}
.s1 { color: #cc7832;}
.s2 { color: #6a8759;}
.s3 { color: #6897bb;}
</style>
</head>
<body bgcolor="#2b2b2b">
<table CELLSPACING=0 CELLPADDING=5 COLS=1 WIDTH="100%" BGCOLOR="#606060" >
<tr><td><center>
<font face="Arial, Helvetica" color="#000000">
LoginFrame.java</font>
</center></td></tr></table>
<pre>
<span class="s1">import </span><span class="s0">java.awt.Font</span><span class="s1">;</span>
<span class="s1">import </span><span class="s0">java.awt.Graphics</span><span class="s1">;</span>
<span class="s1">import </span><span class="s0">java.awt.Image</span><span class="s1">;</span>
<span class="s1">import </span><span class="s0">java.awt.event.ActionEvent</span><span class="s1">;</span>
<span class="s1">import </span><span class="s0">java.awt.event.ActionListener</span><span class="s1">;</span>
<span class="s1">import </span><span class="s0">java.io.File</span><span class="s1">;</span>
<span class="s1">import </span><span class="s0">java.io.IOException</span><span class="s1">;</span>
<span class="s1">import </span><span class="s0">javax.imageio.ImageIO</span><span class="s1">;</span>
<span class="s1">import </span><span class="s0">javax.swing.BorderFactory</span><span class="s1">;</span>
<span class="s1">import </span><span class="s0">javax.swing.ImageIcon</span><span class="s1">;</span>
<span class="s1">import </span><span class="s0">javax.swing.JButton</span><span class="s1">;</span>
<span class="s1">import </span><span class="s0">javax.swing.JFrame</span><span class="s1">;</span>
<span class="s1">import </span><span class="s0">javax.swing.JLabel</span><span class="s1">;</span>
<span class="s1">import </span><span class="s0">javax.swing.JOptionPane</span><span class="s1">;</span>
<span class="s1">import </span><span class="s0">javax.swing.JPanel</span><span class="s1">;</span>
<span class="s1">import </span><span class="s0">javax.swing.JPasswordField</span><span class="s1">;</span>
<span class="s1">import </span><span class="s0">javax.swing.JTextField</span><span class="s1">;</span>
<span class="s1">public class </span><span class="s0">LoginFrame </span><span class="s1">extends </span><span class="s0">JFrame{</span>
    <span class="s0">JLabel userLabel</span><span class="s1">;</span>
    <span class="s0">JTextField userField</span><span class="s1">;</span>
    <span class="s0">JLabel userLabel2</span><span class="s1">;</span>
    <span class="s0">JPasswordField userField2</span><span class="s1">;</span>
    <span class="s0">JButton Login</span><span class="s1">,</span><span class="s0">Cancel</span><span class="s1">;</span>

    <span class="s1">public </span><span class="s0">LoginFrame() {</span>
        <span class="s0">userLabel = </span><span class="s1">new </span><span class="s0">JLabel(</span><span class="s2">&quot;账号&quot;</span><span class="s0">)</span><span class="s1">;</span>

        <span class="s0">userLabel.setFont(</span><span class="s1">new </span><span class="s0">Font(</span><span class="s2">&quot;微软雅黑&quot;</span><span class="s1">,</span><span class="s0">Font.BOLD</span><span class="s1">,</span><span class="s3">18</span><span class="s0">))</span><span class="s1">;</span>
        <span class="s0">userLabel2 = </span><span class="s1">new </span><span class="s0">JLabel(</span><span class="s2">&quot;密码&quot;</span><span class="s0">)</span><span class="s1">;</span>
        <span class="s0">userLabel2.setFont(</span><span class="s1">new </span><span class="s0">Font(</span><span class="s2">&quot;微软雅黑&quot;</span><span class="s1">,</span><span class="s0">Font.BOLD</span><span class="s1">,</span><span class="s3">18</span><span class="s0">))</span><span class="s1">;</span>

        <span class="s0">userLabel.setBounds(</span><span class="s3">20</span><span class="s1">, </span><span class="s3">220</span><span class="s1">, </span><span class="s3">100</span><span class="s1">, </span><span class="s3">30</span><span class="s0">)</span><span class="s1">;</span>
        <span class="s1">this</span><span class="s0">.add(userLabel)</span><span class="s1">;</span>
        <span class="s0">userLabel2.setBounds(</span><span class="s3">20</span><span class="s1">, </span><span class="s3">280</span><span class="s1">, </span><span class="s3">100</span><span class="s1">, </span><span class="s3">30</span><span class="s0">)</span><span class="s1">;</span>
        <span class="s1">this</span><span class="s0">.add(userLabel2)</span><span class="s1">;</span>

        <span class="s0">userField = </span><span class="s1">new </span><span class="s0">JTextField()</span><span class="s1">;</span>
        <span class="s0">userField.setBounds(</span><span class="s3">80</span><span class="s1">, </span><span class="s3">220</span><span class="s1">, </span><span class="s3">100</span><span class="s1">, </span><span class="s3">30</span><span class="s0">)</span><span class="s1">;</span>
        <span class="s0">userField.setBorder(BorderFactory.createLoweredBevelBorder())</span><span class="s1">;</span>
        <span class="s0">userField.setOpaque(</span><span class="s1">false</span><span class="s0">)</span><span class="s1">;</span>
        <span class="s1">this</span><span class="s0">.add(userField)</span><span class="s1">;</span>

        <span class="s0">userField2 = </span><span class="s1">new </span><span class="s0">JPasswordField()</span><span class="s1">;</span>
        <span class="s0">userField2.setBounds(</span><span class="s3">80</span><span class="s1">, </span><span class="s3">280</span><span class="s1">, </span><span class="s3">100</span><span class="s1">, </span><span class="s3">30</span><span class="s0">)</span><span class="s1">;</span>
        <span class="s0">userField2.setBorder(BorderFactory.createLoweredBevelBorder())</span><span class="s1">;</span>
        <span class="s0">userField2.setOpaque(</span><span class="s1">false</span><span class="s0">)</span><span class="s1">;</span>
        <span class="s1">this</span><span class="s0">.add(userField2)</span><span class="s1">;</span>


        <span class="s0">Login = </span><span class="s1">new </span><span class="s0">JButton(</span><span class="s2">&quot;登录&quot;</span><span class="s0">)</span><span class="s1">;</span>
        <span class="s0">Login.setBounds(</span><span class="s3">45</span><span class="s1">,</span><span class="s3">350</span><span class="s1">,</span><span class="s3">60</span><span class="s1">,</span><span class="s3">36</span><span class="s0">)</span><span class="s1">;</span>
        <span class="s0">Login.addActionListener(</span><span class="s1">new </span><span class="s0">ActionListener() {</span>

            <span class="s0">@Override</span>
            <span class="s1">public void </span><span class="s0">actionPerformed(ActionEvent e) {</span>
                <span class="s0">String userName = userField.getText()</span><span class="s1">;</span>
                <span class="s0">String passWord = userField2.getText()</span><span class="s1">;</span>
                <span class="s1">if</span><span class="s0">(</span><span class="s2">&quot;Lucy&quot;</span><span class="s0">.equals(userName) &amp;&amp; </span><span class="s2">&quot;123456&quot;</span><span class="s0">.equals(passWord)){</span>

                    <span class="s0">JOptionPane.showMessageDialog(</span><span class="s1">null, </span><span class="s2">&quot;欢迎&quot;</span><span class="s0">+userName+</span><span class="s2">&quot;来到天天酷跑游戏&quot;</span><span class="s0">)</span><span class="s1">;</span>
                    <span class="s1">new </span><span class="s0">MainFrame()</span><span class="s1">;</span>

                    <span class="s0">dispose()</span><span class="s1">;</span>
                <span class="s0">}</span><span class="s1">else if</span><span class="s0">(</span><span class="s2">&quot;&quot;</span><span class="s0">.equals(userName) || </span><span class="s2">&quot;&quot;</span><span class="s0">.equals(passWord)){</span>

                    <span class="s0">JOptionPane.showMessageDialog(</span><span class="s1">null, </span><span class="s2">&quot;用户名 / 密码不能为空，请重新输入！&quot;</span><span class="s0">)</span><span class="s1">;</span>
                <span class="s0">}</span><span class="s1">else</span><span class="s0">{</span>
                    <span class="s0">JOptionPane.showMessageDialog(</span><span class="s1">null, </span><span class="s2">&quot;用户名 / 密码输入错误，请重新输入！&quot;</span><span class="s0">)</span><span class="s1">;</span>
                <span class="s0">}</span>

            <span class="s0">}</span>
        <span class="s0">})</span><span class="s1">;</span>
        <span class="s1">this</span><span class="s0">.add(Login)</span><span class="s1">;</span>

        <span class="s0">Cancel = </span><span class="s1">new </span><span class="s0">JButton(</span><span class="s2">&quot;取消&quot;</span><span class="s0">)</span><span class="s1">;</span>
        <span class="s0">Cancel.setBounds(</span><span class="s3">135</span><span class="s1">,</span><span class="s3">350</span><span class="s1">,</span><span class="s3">60</span><span class="s1">,</span><span class="s3">36</span><span class="s0">)</span><span class="s1">;</span>
        <span class="s1">this</span><span class="s0">.add(Cancel)</span><span class="s1">;</span>
        <span class="s0">Cancel.addActionListener(</span><span class="s1">new </span><span class="s0">ActionListener() {</span>

            <span class="s0">@Override</span>
            <span class="s1">public void </span><span class="s0">actionPerformed(ActionEvent e) {</span>

                <span class="s0">dispose()</span><span class="s1">;</span>
            <span class="s0">}</span>
        <span class="s0">})</span><span class="s1">;</span>

        <span class="s0">LoginPanel panel = </span><span class="s1">new </span><span class="s0">LoginPanel()</span><span class="s1">;</span>
        <span class="s1">this</span><span class="s0">.add(panel)</span><span class="s1">;</span>

        <span class="s1">this</span><span class="s0">.setSize(</span><span class="s3">900</span><span class="s1">,</span><span class="s3">530</span><span class="s0">)</span><span class="s1">;</span>
        <span class="s1">this</span><span class="s0">.setLocationRelativeTo(</span><span class="s1">null</span><span class="s0">)</span><span class="s1">;</span>
        <span class="s1">this</span><span class="s0">.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)</span><span class="s1">;</span>
        <span class="s1">this</span><span class="s0">.setUndecorated(</span><span class="s1">true</span><span class="s0">)</span><span class="s1">;</span>
        <span class="s1">this</span><span class="s0">.setIconImage(</span><span class="s1">new </span><span class="s0">ImageIcon(</span><span class="s2">&quot;Image/115.png&quot;</span><span class="s0">).getImage())</span><span class="s1">;</span>
        <span class="s1">this</span><span class="s0">.setVisible(</span><span class="s1">true</span><span class="s0">)</span><span class="s1">;</span>
    <span class="s0">}</span>

    <span class="s1">public static void </span><span class="s0">main(String[] args) {</span>
        <span class="s1">new </span><span class="s0">LoginFrame()</span><span class="s1">;</span>
    <span class="s0">}</span>
    <span class="s1">class </span><span class="s0">LoginPanel </span><span class="s1">extends </span><span class="s0">JPanel{</span>

        <span class="s0">Image background</span><span class="s1">;</span>
        <span class="s1">public </span><span class="s0">LoginPanel() {</span>
            <span class="s1">try </span><span class="s0">{</span>
                <span class="s0">background = ImageIO.read(</span><span class="s1">new </span><span class="s0">File(</span><span class="s2">&quot;Image/login.jpg&quot;</span><span class="s0">))</span><span class="s1">;</span>
            <span class="s0">} </span><span class="s1">catch </span><span class="s0">(IOException e) {</span>

                <span class="s0">e.printStackTrace()</span><span class="s1">;</span>
            <span class="s0">}</span>
        <span class="s0">}</span>

        <span class="s0">@Override</span>
        <span class="s1">public void </span><span class="s0">paint(Graphics g) {</span>
            <span class="s1">super</span><span class="s0">.paint(g)</span><span class="s1">;</span>

            <span class="s0">g.drawImage(background</span><span class="s1">, </span><span class="s3">0</span><span class="s1">, </span><span class="s3">0</span><span class="s1">,</span><span class="s3">900</span><span class="s1">,</span><span class="s3">530</span><span class="s1">, null</span><span class="s0">)</span><span class="s1">;</span>
        <span class="s0">}</span>
    <span class="s0">}</span>

<span class="s0">}</span></pre>
</body>
</html>